import axios from 'axios'
import qs from 'qs'

// const BASEURL = '/api';
const BASEURL = 'http://rytest.wawa89.net/index.php/home/';
export const baseUrl = 'http://rytest.wawa89.net';

const instance = axios.create({
  baseURL: BASEURL,
  timeout: 8000,
  headers: {
    'X-Requested-With': 'XMLHttpRequest',
    'Content-Type': 'application/x-www-form-urlencoded',
  },
});

// // 请求拦截器 发送请求之前做一些处理
instance.interceptors.request.use(function(config) {

  //   if (sessionStorage.uid) {
  //   // 初始化openid
  //   if (config.url.indexOf('uid') > 0) {
  //     config.url = config.url
  //   } else if (config.url.indexOf('?') > 0) {
  //     config.url += '&openid=' + sessionStorage.openid
  //   } else {
  //     config.url += '?openid=' + sessionStorage.openid
  //   }
  // }
  // 数据的处理
  if (config.method === 'post' || config.method === 'put') {
    config.data = qs.stringify(config.data)
  }
  return config
}, function(error) {
  // 当请求异常时做一些处理
  return Promise.reject(error)
})


// 获取banner(banner_lm     0:首页banner 1:门店banner 2:商城banner)
export function getBanner(banner_lm) {
  return instance({
    url: `Banner/index?banner_lm=${banner_lm}`,
    method: 'GET'
  })
}

// 首页
// 获取资讯
export function getNewList(pageNum, pageSize) {
  return instance({
    url: `news/getNewLists?page=${pageNum}&pageSize=${pageSize}`,
    method: 'GET'
  })
}
// 资讯详情
export function getNewShow(newsId) {
  return instance({
    url: `news/getNewShow?id=${newsId}`,
    method: 'GET'
  })
}
// 获取附近门店
export function getDoorStoreLists(dataJson) {
  return instance({
    url: `DoorStore/getDoorStoreLists`,
    method: 'POST',
    data: dataJson
  })
}

// 门店模块
// 门店首页
export function getDoorStoreLists1(dataJson) {
  return instance({
    url: `DoorStore/getDoorStoreLists1`,
    method: 'POST',
    data: dataJson
  })
}
// 门店详情
export function getDoorStoreShow(dataJson) {
  return instance({
    url: `DoorStore/getDoorStoreShow`,
    method: 'POST',
    data: dataJson
  })
}
// 门店附属眼镜店
export function getFuShuGlassesStore(dataJson) {
  return instance({
    url: `DoorStore/getFuShuGlassesStore`,
    method: 'POST',
    data: dataJson
  })
}
// 门店预约
export function doorPre(dataJson) {
  return instance({
    url: `DoorStore/doorPre`,
    method: 'POST',
    data: dataJson
  })
}
// 根据门店id获取门店
export function getStoreById(storeId) {
  return instance({
    url: `DoorStore/getDoorStoreShow_forDoorStoreId?id=${storeId}`,
    method: 'GET'
  })
}
// 门店搜索内容
export function getSearchDoorStoreLists(dataJson) {
  return instance({
    url: `DoorStore/getSearchDoorStoreLists`,
    method: 'POST',
    data: dataJson
  })
}


// 商城模块
// 获取首页商城内容
export function getGoodsIndex() {
  return instance({
    url: `mall/getTuiJianFrontThree`,
    method: 'GET'
  })
}

// 商城首页--获取分类列表 (默认三个)
export function getClassify() {
  return instance({
    url: `mall/getMallProLmLists?limit=3`,
    method: 'GET'
  })
}

// 获取商城列表
export function getGoodsList(page, pageSize, mall_pro_lm_id) {
  return instance({
    url: `mall/getMallProCoLists?page=${page}&pageSize=${pageSize}&mall_pro_lm_id=${mall_pro_lm_id}`,
    method: 'GET'
  })
}

// 获取商品详情
export function getGoodsDetails(goodsId) {
  return instance({
    url: `mall/getMallProCoShow?id=${goodsId}`,
    method: 'GET'
  })
}

// 加入购物车
export function addCarts(dataJson) {
  return instance({
    url: `mall/cart_add`,
    method: 'POST',
    data: dataJson
  })
}

// 获取购物车列表
export function getCarts(uid) {
  return instance({
    url: `mall/getCartLists?uid=${uid}`,
    method: 'GET'
  })
}

// 删除购物车数据
export function cartDel(uid, cart_id) {
  return instance({
    url: `mall/cart_del?uid=${uid}&cart_id=${cart_id}`,
    method: 'GET'
  })
}

// 修改购物车数量
export function cartEdit(dataJson) {
  return instance({
    url: `mall/cart_edit`,
    method: 'POST',
    data: dataJson
  })
}
// 直接购买
export function submitOrder(dataJson) {
  return instance({
    url: `mall/submitOrder`,
    method: 'POST',
    data: dataJson
  })
}
// 获取当前用户的最新收货信息
export function getAddress(uid) {
  return instance({
    url: `User/getDefaultReceivingInfo?uid=${uid}`,
    method: 'GET',
  })
}
// 保存当前用户的最新收货信息
export function setAddress(dataJson) {
  return instance({
    url: `User/setDefaultReceivingInfo`,
    method: 'POST',
    data: dataJson
  })
}
// 根据购物车id获取商品
export function getProLists_forCart(ids, uid) {
  return instance({
    url: `Mall/getProLists_forCart?ids=${ids}&uid=${uid}`,
    method: 'GET'
  })
}

// 个人中心模块
// 发送验证码
export function sendCode(mobile) {
  return instance({
    url: `SendCode/sendCode1?mobile=${mobile}`,
    method: 'GET'
  })
}
// 绑定手机号
export function bindMobile(dataJson) {
  return instance({
    url: `user/bingPhone`,
    method: 'POST',
    data: dataJson
  })
}
export function personCenter(uid) {
  return instance({
    url: `user/getUserInfo?uid=${uid}`,
    method: 'GET'
  })
}
// 我的邀请
export function getMyInvitation(uid) {
  return instance({
    url: `user/getMyInvitation?uid=${uid}`,
    method: 'GET'
  })
}
// 充值记录
export function getMoneyRecord(uid) {
  return instance({
    url: `Money/getMoneyRecord?uid=${uid}`,
    method: 'GET'
  })
}
// 我的预约
export function getMyPre(dataJson) {
  return instance({
    url: `user/getMyPre?uid=${dataJson.uid}&lat=${dataJson.lat}&lon=${dataJson.lon}`,
    method: 'GET',
  })
}
// 收益记录
export function getEarningsLog(uid) {
  return instance({
    url: `Money/getEarningsLog?uid=${uid}`,
    method: 'GET'
  })
}
// 提现记录
export function getWithLog(uid) {
  return instance({
    url: `Money/getWithLog?uid=${uid}`,
    method: 'GET'
  })
}
// 提现
export function withdrawal_huiyuan(dataJson) {
  return instance({
    url: `Money/withdrawal_huiyuan`,
    method: 'POST',
    data: dataJson
  })
}
// 提现计算服务费
export function getFuWuFei() {
  return instance({
    url: `Money/getFuWuFei`,
    method: 'GET'
  })
}
// 订单列表
export function getOrderList(uid, status, pageNum, pageSize) {
  return instance({
    url: `mall/getMallOrderLists?uid=${uid}&type=${status}&page=${pageNum}&pageSize=${pageSize}`,
    method: 'GET'
  })
}
// 订单详情
export function getOrderDetails(uid, order_id) {
  return instance({
    url: `mall/getMallOrderShow?uid=${uid}&mall_order_lm_id=${order_id}`,
    method: 'GET'
  })
}
// 充值余额列表
export function getMoneyLists() {
  return instance({
    url: `Money/getMoneyLists`,
    method: 'GET'
  })
}
// 充值余额
export function nowMoneyAdd(dadtaJson) {
  return instance({
    url: `Money/nowMoneyAdd`,
    method: 'POST',
    data: dadtaJson
  })
}

// 测试模块
// 测试首页
export function examIndex(uid, type) {
  return instance({
    url: `Detection/index?uid=${uid}&type=${type}`,
    method: 'GET'
  })
}

// 获取题目列表
export function getTimu(dataJson) {
  return instance({
    url: `Detection/timu_list`,
    method: 'POST',
    data: dataJson
  })
}
// 保存答案
export function timuSave(dataJson) {
  return instance({
    url: `Detection/timu_save`,
    method: 'POST',
    data: dataJson
  })
}
// 返回结果
export function answer_return(dataJson) {
  return instance({
    url: `Detection/answer_return`,
    method: 'POST',
    data: dataJson
  })
}
// 购买测试机会
export function dopay(dataJson) {
  return instance({
    url: `Detection/dopay`,
    method: 'POST',
    data: dataJson
  })
}
// 我的测试结果
export function examList(dataJson) {
  return instance({
    url: `Detection/order_list`,
    method: 'POST',
    data: dataJson
  })
}

// 分享接口
export function share(dataJson) {
  return instance({
    url: `Index/share_data`,
    method: 'POST',
    data: dataJson
  })
}